package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.nursing.domain.Data;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.dto.FamilyMemberDto;
import com.zzyl.nursing.dto.QueryDeviceDataDto;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IDeviceDataService;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.DeviceDataByDayAndWeekVo;
import com.zzyl.nursing.vo.FamilyElderListVo;
import com.zzyl.nursing.vo.FamilyElderVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 * 
 * @author ruoyi
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;
    @Autowired
    private IDeviceDataService deviceDataService;


    @PostMapping("/login")
    @ApiOperation("小程序登录")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo loginVo = familyMemberService.login(dto);
        return success(loginVo);
    }

    @PostMapping("/add")
    @ApiOperation("绑定家人")
    public AjaxResult addFamily(@RequestBody FamilyMemberDto dto) {
        familyMemberService.addFamily(dto);
        return AjaxResult.success();
    }

    /**
     * 查询家人列表
     */
    @GetMapping("/my")
    public R<List<FamilyElderVo>> selectMy() {
        List<FamilyElderVo> familyElderVoList = familyMemberService.selectMy();
        return R.ok(familyElderVoList);


    }

    /**
     * 按天统计查询指标数据
     */
    @GetMapping("/queryDeviceDataListByDay")
    public R<List<DeviceDataByDayAndWeekVo>> queryDeviceDataListByDay(QueryDeviceDataDto dto){
        List<DeviceDataByDayAndWeekVo> dateTimeList = familyMemberService.queryDeviceDateCountByDay(dto);
        System.out.println(dateTimeList);
        return R.ok(dateTimeList);
    }

    /**
     *  按周统计查询指标数据
     * @param dto
     * @return
     */
    @GetMapping("/queryDeviceDataListByWeek")
    public R<List<DeviceDataByDayAndWeekVo>> queryDeviceDataListByWeek(QueryDeviceDataDto dto){
        List<DeviceDataByDayAndWeekVo> dateTimeList = familyMemberService.queryDeviceDateCountByWeek(dto);
        System.out.println(dateTimeList);
        return R.ok(dateTimeList);
    }
     @GetMapping("/list-by-page")
    @ApiOperation("分页查询家人列表")
    public R<List<FamilyElderListVo>> selectPage() {
        List<FamilyElderListVo> list = familyMemberService.selectPage();
        return R.ok(list);
    }

    @PostMapping ("/QueryDevicePropertyStatus")
    @ApiOperation("查询老人随身设备数据")
    public R<Data> QueryDevicePropertyStatus(@RequestBody DeviceData deviceData){
        Data data = familyMemberService.QueryDevicePropertyStatus(deviceData);
        return R.ok(data);
    }
}








